#ifndef __SYS_CONFIG
#define __SYS_CONFIG

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "ohos_init.h"
#include "cmsis_os2.h"

#include "hal_bsp_pcf8574.h"
#include "hal_bsp_ssd1306.h"
#include "hal_bsp_ssd1306_bmps.h"
#include "hal_bsp_ap3216c.h"
#include "hal_bsp_sht20.h"
#include "hal_bsp_wifi.h"
#include "hal_bsp_nfc.h"
#include "hal_bsp_nfc_to_wifi.h"
#include "hal_bsp_mqtt.h"
#include "oled_show_log.h"
#include "wifi_device.h"
#include "lwip/netifapi.h"
#include "lwip/sockets.h"
#include "lwip/api_shell.h"
#include "hi_uart.h"
#include "hi_io.h"
#include "hi_gpio.h"
#include "cJSON.h"

#include "oled_show.h"
#include "dev_control_task.h"
#include "mqtt_task.h"


#include "mywifi.h"
#include "mynfc.h"
#include "nfcConfigWifi.h"

// 设备ID
#define DEVICE_ID "67aaa88d61f92d003ad05291_hi3861"
// MQTT客户端ID
#define MQTT_CLIENT_ID "67aaa88d61f92d003ad05291_hi3861_0_0_2025021206"
// MQTT用户名
#define MQTT_USER_NAME "67aaa88d61f92d003ad05291_hi3861"
// MQTT密码
#define MQTT_PASS_WORD "65b07c5d031075179d2b8aaa7accb28f0464777b252c92edb2cb3e6835abe608"
// 华为云平台的IP地址
#define SERVER_IP_ADDR "116.205.178.237"
// 华为云平台的IP端口号
#define SERVER_IP_PORT 1883
// 订阅 接收控制命令的主题
#define MQTT_TOPIC_SUB_COMMANDS "$oc/devices/%s/sys/commands/#"
// 发布 成功接收到控制命令后的主题
#define MQTT_TOPIC_PUB_COMMANDS_REQ "$oc/devices/%s/sys/commands/response/request_id=%s"
#define MALLOC_MQTT_TOPIC_PUB_COMMANDS_REQ "$oc/devices//sys/commands/response/request_id="

// 发布 设备属性数据的主题
#define MQTT_TOPIC_PUB_PROPERTIES "$oc/devices/%s/sys/properties/report"
#define MALLOC_MQTT_TOPIC_PUB_PROPERTIES "$oc/devices//sys/properties/report"

#define TASK_STACK_SIZE (1024 * 10)
#define MsgQueueObjectNumber 16 // 定义消息队列对象的个数

#define MQTT_SEND_TASK_TIME 3 // s
#define MQTT_RECV_TASK_TIME 1 // s
#define TASK_INIT_TIME 2 // s
#define DISPLAY_BUFF_MAX 64
#define MQTT_TOPIC_LEN 128
#define MQTT_DATA_MAX 512


// 设备开启关闭状态
typedef enum {
    POWER_STATUS_ON   = 0x00,//蜂鸣器开启
    POWER_STATUS_OFF  = 0x01,//蜂鸣器关闭
} te_power_status_t;

// 三色灯当前状态
typedef struct {
    te_power_status_t lamp_power; //开关
    uint8_t strength; // 亮度
    uint8_t timer; //定时时间
    uint8_t RGB_color_r; 
    uint8_t RGB_color_g; 
    uint8_t RGB_color_b; 
} te_lamp_status_t;

// 蜂鸣器当前状态
typedef struct {
    te_power_status_t beep_power; //开关
    uint16_t frequency; //频率
    uint8_t timer; //定时时间
} te_beep_status_t;

// 风扇当前状态
typedef struct {
    te_power_status_t fan_power; //开关
    uint16_t speed; //速度
    uint8_t timer; //定时时间
} te_fan_status_t;

// 设备当前所有状态
typedef struct{
    char local_ip_address[20];  //IP地址

    //传感器数据
    uint8_t light;
    float temperature;
    float humidity;
    uint16_t infrared; //红外

    //外设工作状态
    te_beep_status_t beep_state;       //蜂鸣器状态
    te_lamp_status_t lamp_state;        //三色灯状态
    te_fan_status_t fan_state;         //风扇状态
}Dev_status;

// 回传结果
typedef enum {
    RESPONSE_SUCCESS    = 0x00, //执行成功
    RESPONSE_ANA_FAILED = 0x01, //JSON解析失败
    RESPONSE_UNDEFINE   = 0x02, //指令不识别
    RESPONSE_DATA_MISS  = 0x03, //数据包丢失
    RESPONSE_SET_FAILED = 0x04, //设置属性失败
} te_response_t;


extern Dev_status globals_dev_status; //定义在main.c

extern osMutexId_t globals_Mutex_ID;
extern osMutexId_t uart_update_Mutex_ID;


#include "json.h"

#endif

